﻿using Compass.Wasm.Shared.Wms;
using Compass.Wasm.Shared;
using Compass.WmsService.Infrastructure;
using System.ComponentModel.DataAnnotations;
using Compass.Wasm.Server.Services.Wms;

namespace Compass.Wasm.Server.Controllers.Wms;

[Route("api/[controller]")]
[ApiController]
[UnitOfWork(typeof(WmsDbContext))]
public class StockOutController : ControllerBase
{
    #region ctor
    private readonly IStockOutService _service;
    public StockOutController(IStockOutService service)
    {
        _service = service;
    }
    #endregion

    #region 基本增删改查
    [HttpGet("All")]
    public async Task<ApiResponse<IEnumerable<StockOutDto>>> GetAll() => await _service.GetAllAsync();

    [HttpGet("{id}")]
    public async Task<ApiResponse<StockOutDto>> GetSingle([RequiredGuid] Guid id) => await _service.GetSingleAsync(id);

    [HttpPost("Add")]
    public async Task<ApiResponse<StockOutDto>> Add(StockOutDto dto) => await _service.AddAsync(dto);

    [HttpPut("{id}")]
    public async Task<ApiResponse<StockOutDto>> Update([RequiredGuid] Guid id, StockOutDto dto) => await _service.UpdateAsync(id, dto);

    [HttpDelete("{id}")]
    public async Task<ApiResponse<StockOutDto>> Delete([RequiredGuid] Guid id) => await _service.DeleteAsync(id);

    #endregion

    #region 扩展查询
    [HttpGet("FromLast")]
    public async Task<ApiResponse<IEnumerable<StockOutDto>>> GetLastByCargo(Guid cargoId, DateTime last) => await _service.GetFromLastByCargoAsync(cargoId, last);
    //http://10.9.18.31/api/StockOut/FromLast?cargoId=cargoId&last=last

    [HttpGet("Cargo")]
    public async Task<ApiResponse<IEnumerable<StockOutDto>>> GetAllByCargo(Guid cargoId) => await _service.GetAllByCargoAsync(cargoId);
    //http://10.9.18.31/api/StockOut/Cargo?cargoId=cargoId


    [HttpGet("Period")]
    public async Task<ApiResponse<IEnumerable<StockOutDto>>> GetAllByPeriod(DateTime start, DateTime end) => await _service.GetAllByPeriodAsync(start, end);
    //http://10.9.18.31/api/StockOut/Period?start=start&end=end

    #endregion
}